"""
自定义示例选择器
"""
from langchain_core.example_selectors import BaseExampleSelector

# 自定义示例选择器，根据单词的长度选择要选择的示例。继承BaseExampleSelector, 并实现select_examples方法
class CustomExampleSelector(BaseExampleSelector):

    def __init__(self, examples):
        self.examples = examples

    def add_example(self, example):
        self.examples.extend(example)

    def select_examples(self, input_variables: dict[str, str]) -> list[dict]:
        for example in self.examples:
            if len(example) == len(input_variables["input"]):
                return example
        return []

selector = CustomExampleSelector([])
selector.add_example(["input", "hand", "output", "mano"])
print(selector.select_examples({"input": "abcd"}))
